//  https://lbs.qq.com/miniProgram/jsSdk/jsSdkGuide/methodGeocoder

/** promise
 * showToast 提示
 * @param {object,string} params 参数
 */ 
export const showToast = ({title}, flag, isMask) => {
    return new Promise((resolve, reject) => {
        flag ==='success' ? flag = 'success' : flag = 'none'
        isMask ==='mask' ? true : false
        wx.showToast({
            title,
            icon: flag,
            mask: isMask,
            success: (res) => {
                resolve(res)
            },
            fail: () => {
                reject(err)
            }
          })
    })
}
/** promise
 * 权限处理
 * @返回授权的权限
 */
export const getSetting = () => {
    return new Promise((resolve, reject) => {
        wx.getSetting({
            success: (result) => {
                resolve(result)
            },
            fail: (err) => {
                reject(err)
            }
        })
    })
}

/** promise
 * 获取当前的地理位置
 * @返回坐标系列信息
 */
export const getLocation = (type) => {
    return new Promise((resolve, reject) => {
        wx.getLocation({
            ...type,
            success: (res) => {
                resolve(res)
            },
            fail: (err) => {
                reject(err)
            }
        })
    })
}
/** promise
 * 获取地图中心点的位置 
 *  @返回gcj02坐标
 */
export const getCenterLocation = (obj, type) => {
    return new Promise((resolve, reject) => {
        obj.getCenterLocation({
            ...type,
            success: (res) => {
                resolve(res)
            },
            fail: (err) => {
                reject(err)
            }
        })
    })
}
/** promise
 * 移动地图中心点的位置 
 *  @
 */
export const MoveToLocation = (obj) => {
    return new Promise((resolve, reject) => {
        obj.moveToLocation({
            success: (res) => {
                resolve(res)
            },
            fail: (err) => {
                reject(err)
            }
        })
    })
}
/** promise
 * 调起腾讯地图三方库 api
 * @逆地址解析(坐标位置描述)
 */
export const reverseAddr = (obj, params) => {
    return new Promise((resolve, reject) => {
        obj.reverseGeocoder({
            ...params,
            success: (res) => {
                resolve(res)
            },
            fail: (err) => {
                reject(err)
            }
        })
    })
}
/** promise
 * 调起腾讯地图三方库 api
 *  @返回 markers @相关数据
 */
export const search = (obj, params) => {
    return new Promise((resolve, reject) => {
        obj.search({
            ...params,
            success: (res) => {
                resolve(res)
            },
            fail: (res) => {
                reject(res);
            }
      })
    })
}
/** promise
 * 调起腾讯地图三方库 api
 *  @返回 搜索提示 @相关数据
 */
export const Suggestion = (obj, params) => {
    return new Promise((resolve, reject) => {
        obj.getSuggestion({
            ...params,
            success: (res) => {
                resolve(res)
            },
            fail: (res) => {
                reject(res);
            }
      })
    })
}
/** promise
 * 调起腾讯地图三方库 api
 *  @返回 polyline @相关数据
 */
export const polyline = (obj, params) => {
    return new Promise((resolve, reject) => {
        obj.direction({
            ...params,
            success: (res) => {
                resolve(res)
            },
            fail: (err) => {
                console.log(err)
            }
        })
    })
}
/** promise
 * 调起腾讯地图三方库 api
 *  @返回 Distance @计算距离相关数据
 *  @distance 起点到终点的距离，单位：米，
 *  @duration 表示从起点到终点的结合路况的时间，秒为单位
 */
export const Distance = (obj, params) => {
    return new Promise((resolve, reject) => {
        obj.calculateDistance({
            ...params,
            success: (res) =>{
                resolve(res)
            },
            fail: (err) => {
                reject(err)
            }
        })
    })
}
/** promise
 * 调起腾讯地图三方库 api
 *  @返回 CityList 城市列表
 *  @result [1 省  2 市  3 区县]
 */
export const CityList = (obj) => {
    return new Promise((resolve, reject) => {
        obj.getCityList({
            success: (res) => {
                resolve(res)
            },
            fail: (err) => {
                reject(err)
            }
        })
    })
}
/** promise
 * 调起腾讯地图三方库 api
 *  @传入对应省份ID获得城市数据，传入城市ID获得区县数据
 *  @返回 getCityList返回数据的Id   如：北京是'110000'
 *  @result [1 省  2 市  3 区县]
 */
export const ByCityId = (obj, params) => {
    return new Promise((resolve, reject) => {
        obj.getDistrictByCityId({
            ...params,
            success: (res) => {
                resolve(res)
            },
            fail: (err) => {
                reject(err)
            }
        })
    })
}